var mongoose=require('mongoose');
var Post=mongoose.model('Post',{
    title:String,
    authors:[String],
    comments:[
        {
            content:String,
            like:Number
        }
    ],
    slice:Array,
    emails:[String]
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');

Post.update({
    title:'post5'
},{
    $addToSet:{
        emails:'e1'
    }
},{upsert:true},(err,r)=>{
    console.log('Update:',err,r);

    Post.update({
        title:'post5'
    },{
        $addToSet:{
            emails:'e2'
        }
    },{upsert:true},(err,r)=>{
        console.log('Update:',err,r);

        Post.update({
            title:'post5'
        },{
            $addToSet:{
                emails:'e2'
            }
        },{upsert:true},(err,r)=>{
            console.log('Update:',err,r);


            Post.find({title:'post5'},(e,r)=>{
                console.log('Find:\n',e,r);
                process.exit(1);
            });

        });

    });

});


/*
 * $addToSet:{field:val}
 *
 * 添加与字段已有值不重复的值
 * 字段类型必须是数组
 * */





